package com.baozhun.mall.common.widget.loading

import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.baozhun.mall.common.R
import com.chad.library.adapter.base.loadmore.BaseLoadMoreView
import com.chad.library.adapter.base.util.getItemView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import org.jetbrains.annotations.NotNull

/**
 * @Title： 自定义加载更多view
 * @Description：
 * @Author：xuefeng.zhu
 * @Since：2022/11/3
 * @Version：1.0.0
 */
class CustomLoadMoreView : BaseLoadMoreView() {
    var mLoadMoreEndText = ""

    @NotNull
    override fun getRootView(@NotNull parent: ViewGroup): View {
        // 整个 LoadMore 布局
        return parent.getItemView(R.layout.view_load_more)
    }

    @NotNull
    override fun getLoadingView(@NotNull holder: BaseViewHolder): View {
        // 布局中 “加载中”的View
        return holder.getView(R.id.load_more_loading_view)
    }

    @NotNull
    override fun getLoadComplete(@NotNull holder: BaseViewHolder): View {
        // 布局中 “当前一页加载完成”的View
        return holder.getView(R.id.load_more_load_complete_view)
    }

    @NotNull
    override fun getLoadEndView(@NotNull holder: BaseViewHolder): View {
        // 布局中 “全部加载结束，没有数据”的View
        var loadEndView: View = holder.getView(R.id.load_more_load_end_view)
        if (mLoadMoreEndText.isNotEmpty()) {
            var loadMoreLoadEnd = loadEndView.findViewById<TextView>(R.id.tv_load_more_load_end)
            loadMoreLoadEnd.text = mLoadMoreEndText
        }
        return loadEndView
    }

    @NotNull
    override fun getLoadFailView(@NotNull holder: BaseViewHolder): View {
        // 布局中 “加载失败”的View
        return holder.getView(R.id.load_more_load_fail_view)
    }

    fun setLoadMoreEndText(loadMoreEndText: String) {
        mLoadMoreEndText = loadMoreEndText
    }
}